const re = require('../../utils/request.js')

Page({
  /**
   * 页面的初始数据
   */
  data: {
    option1: [
      { text: '全部', value: 0 },
    ],
    value1: 0,
    search: "",
    crpItem: [
      {
        "id": 1,
        "name": "遵规守纪",
        "content": "遵守国家法律法规，遵守校规校纪，杜绝违法违纪行为",
        "crpModuleId": 1
      }
    ]
  },
  toSearch(event) {
    console.log(event.detail)
    this.setData({
      search: event.detail
    })

    // 更新crp-item列表
    re.getRequest("/crp-item",
      {
        mid: this.data.value1,
        search: event.detail
      }).then(res => {
        let tmp = res.data
        this.setData({
          crpItem: tmp
        })
      })
  },
  change1: function (event) {
    this.setData({
      value1: event.detail
    })
    // 更新crp-item列表
    re.getRequest("/crp-item",
      {
        mid: event.detail,
        search: this.data.search
      }).then(res => {
        let tmp = res.data
        this.setData({
          crpItem: tmp
        })
      })
  },
  clickItem: function (event) {
    let id = event.target.dataset.id
    // console.log(id);
    wx.navigateTo({
      url: `/pages/apply-1/apply-1?id=${id}`
    })
  },
  methods: {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    re.getRequest("/crp-module").then(res => {
      let tmp = [{ id: 0, name: "全部" }].concat(res.data)
      let option1 = tmp.map(item => ({
        text: item.name,
        value: item.id
      }))

      this.setData({
        option1: option1
      })

    })
  },
  onLoad() {
    re.getRequest("/crp-item").then(res => {
      let tmp = res.data
      this.setData({
        crpItem: tmp
      })
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})